﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace AwesomeGame.UserInput
{
    public class KeyboardHelper
    {
        private KeyboardState _previousState = Keyboard.GetState();
        public List<Keys> KeysOfInterest;

        public delegate void KeyboardEvent(KeyboardHelper sender, Keys key);
        public event KeyboardEvent KeyPressed;
        public event KeyboardEvent KeyReleased;

        public KeyboardHelper(List<Keys> keysOfInterest)
        {
            KeysOfInterest = keysOfInterest;
        }

        public void Update(GameTime gameTime)
        {
            KeyboardState currentState = Keyboard.GetState();

            foreach (Keys key in KeysOfInterest)
            {
                if (_previousState.IsKeyDown(key) != currentState.IsKeyDown(key))
                {
                    if (currentState.IsKeyDown(key))
                    {
                        if (this.KeyPressed != null)
                            KeyPressed(this, key);
                    }
                    else if (_previousState.IsKeyDown(key))
                    {
                        if (this.KeyReleased != null)
                            KeyReleased(this, key);
                    }
                }
            }

            _previousState = currentState;
        }

        public static List<Keys> GetAllNonFancyKeys()
        {
            return new List<Keys> { Keys.A, Keys.B, Keys.C, Keys.D, Keys.E, Keys.F, Keys.G, Keys.H, Keys.I, Keys.J, Keys.K, Keys.L, Keys.M, Keys.N, Keys.O, Keys.P, Keys.Q, Keys.R, Keys.S, Keys.T, Keys.U, Keys.V, Keys.W, Keys.X, Keys.Y, Keys.Z };

        }


    }

    
}
